Types of anomalies in two-dimensional video-based gait analysis in uncontrolled environments

Two-dimensional video-based pose estimation is a technique that can be used to estimate human skeletal coordinates from video data alone. It is also being applied to gait analysis and in particularly, due to its simplicity of measurement, it has the potential to be applied to gait analysis of large populations. However, it is considered difficult to completely homogenize the environment and settings during the measurement of large populations. Therefore, it is necessary to appropriately deal with technical errors that are not related to the biological factors of interest. In this study, by analyzing a large cohort database, we have identified four major types of anomalies that occur during gait analysis using OpenPose in uncontrolled environments: anatomical, biomechanical, and physical anomalies and errors due to estimation. We have also developed a workflow for identifying and correcting these anomalies and confirmed that this workflow is reproducible through simulation experiments. Our results will help obtain a comprehensive understanding of the anomalies to be addressed during pre-processing for 2D video-based gait analysis of large populations.


Introduction
Gait is a simple biomarker of the human condition [1], and its effectiveness as a clinical or preclinical marker for diseases such as nervous system abnormalities and skeletal muscle abnormalities has been revealed in various fields [2][3][4][5][6]. In recent years, with the advancement of artificial intelligence applications, several gait analysis methods based on computer vision have been proposed [7][8][9][10]. These methods are characterized by the extraction of parameters using images or videos of walking as the input. Two such approaches have been proposed to date: one approach is to extract features based on appearance, such as walking silhouette [11,12], and the other is to extract gait parameters, such as a series of joint positions and joint angles, by fitting human joint models to the images using estimation [13].
One algorithm using the latter approach, OpenPose, can estimate joint coordinates at up to 135 key points, such as "body", "feet", "hands" and "face" for multiple subjects in an image by learning a vector space called Part Affinity Fields (PAF) for associations between anatomical joints based on a deep learning model. Previous research has suggested that this joint estimation capability is sufficient to some extent even in videos with many dynamic factors [14]. Compared with conventional optical motion capture, approximately 80% of the estimated joint coordinates are less than 30 mm with good accuracy [15].
These computer vision-based gait analysis methods can automatically analyze a large number of joint coordinates with only digital video as input and can be used in any environment, including homes and clinics, requiring little time, cost, and effort compared with conventional optical motion capture. Large-scale human gait analysis can be conducted more easily than ever before. However, there are some issues to be solved in gait analysis applications, such as a certain amount of unexpected noise and the false detection of multiple persons even though only one person is walking [16]. In addition, a reproducible and standardized analysis workflow is still lacking. Stenum et al. proposed a comprehensive analysis for obtaining gait parameters based on OpenPose during gait in a controlled environment [16]. This workflow uses video as input, preprocessing of joint coordinates obtained from OpenPose, and extraction of gait parameters such as step length.
However, workflows for gait analysis in uncontrolled environments have not been studied sufficiently. To capture gait futures in large populations in heterogenous environments, a robust approach is needed. Various factors are assumed to potentially affect the accuracy of joint estimation using OpenPose, including camera performance, the distance between the camera and the subject, walking speed, clothing, and walking environment. Several existing studies seem to provide a solution, although they assume a somewhat controlled data acquisition environment. Seethapathi et al. reviewed six categories of pose estimation problems that can hinder the estimation of kinematic parameters in the application of OpenPose in motion science, and suggested several possible solutions; for example, post-processing and elaboration during data acquisition, e.g., size estimation incorporating reference objects [17]. The workflow reported by Stenum et al. [16] pointed out false person detection and left-right swapping of lower limbs, but it is manual, with detection, correction, and exclusion being based on visual inspection. In an environment that can be controlled to some extent or that includes few subjects, it may be possible to devise data measurement methods or to deal with measurement errors through manual labor. However, both approaches may be limited when measuring large populations of thousands to tens of thousands of people in several different environments, such as in hospitals and other facilities.
When considering the efficient post-processing approach in such an environment, it is useful to perform a statistical examination of the error structure based on large-scale data. Fortunately, in recent years, a gait database consisting of 10,307 individuals has been made public using OpenPose technology [18]. This database contains pose estimations for an unspecified number of visitors to a certain facility during walking at 25 frames per second (fps) using a multi-view camera in an uncontrolled manner, and 18 joints are estimated for one gait cycle [18]. Although this database was originally intended for the biometrics field, we thought technical anomalous errors in uncontrolled environments could be investigated using this data.
The main purpose of this study was to classify the types of anomalies in pose estimation using OpenPose during the gait cycle in an uncontrolled environment to obtain a roadmap for analyzing large-scale gait data with OpenPose. Through our analysis, we identified four main types of anomalies: anatomical, biomechanical, and physical anomalies and errors due to estimation. In addition, we present a data processing workflow for dealing with the errors that we have categorized and demonstrate its reproducibility through simulation experiments. The code used in this study is online (URL: https://github.com/matsui-lab/PoseFixeR).

Overview of anomaly types
This section provides an overview of the types of anomaly errors in OpenPose measurements during gait that are presented in this paper. Individual anomaly types are discussed in detail in the section below. We conducted a comprehensive analysis of the database (see Materials and Methods), while partially referring to the existing literature [16,17], and identified four main types of anomalous errors that should be preprocessed when estimating joint coordinates during gait using OpenPose in an uncontrolled environment (Fig 1,  Table 1). For convenience, the four types are categorized as anatomical, biomechanical, and physical, as well as errors due to the inherent estimation accuracy of OpenPose. Note that the categories in this study were labeled based on the patterns observed in a data-driven manner, and are used for the convenience of interpretation and to facilitate discussion. Therefore, they are not based on strict anatomical, biomechanical, or physical definitions and these types are not completely independent, as they overlap with each other and, in some cases, are composite. We further subdivided these four categories in terms of detection and correction methods and finally classified them into ten types that we believe should be considered during analysis (Fig 1).

Anatomical constraints
Anatomical constraints refer to a series of anomalous errors that could be considered deviations with respect to standard human anatomical constraints (Fig 1A). The most common case observed here was extreme lengthening at the joint located on the opposite side to the camera direction (Table 1). This is thought to be caused by forcibly making predictions on unobserved joints. We were unable to find any existing studies explicitly addressing and discussing this anomaly. However, in approximately 15% of the subjects, we also observed cases where the shoulder width suddenly increased even though the video was taken from the side (Figs 1C and S3) and cases where the skeletal length of the lower limbs became extremely short or long before or after a certain point in time, regardless of the camera direction ( Fig 1B).
Ideally, we would like to be able to compare the estimated values with the baseline skeletal structure of each person; however, if this is difficult, it may be possible to estimate them by assuming a standard human anatomical skeletal structure and detecting deviations from it. We believe that the relative proportions of standard human skeletal length estimated by a cohort study [19] could be used to predict the joint coordinate values in advance. Specifically, if we consider a normalized coordinate with Neck (Ne) as the origin and apply the standard skeletal length (see Materials and Methods), we can predict the range within which the joint coordinate values should lie. We used this method to identify joint coordinates that were far outside the normal range (see Materials and Methods).  Table 1. Estimation accuracy in Table 1 is excluded from the figure for convenience of illustration. ROM, range of motion; COG, center of gravity. https://doi.org/10.1371/journal.pcbi.1009989.g001

Biomechanical constraints
Anomalous errors deviating from the biomechanical constraints were also observed, mainly in key parameters in the gait analysis, such as the range of motion of the joints (ROM), which is the external angle of the axis connecting Ne and Right Hip (Rh) (or Left Hip [Lh]) and Right Knee (Rk) (or Left Knee [Lk]) ( Fig 1D); center of gravity of the trunk (COG) representing the inclination of the trunk ( Fig 1E); and stride length with ankle distances (Fig 1F). In particular, the anomalies related to ROM were the highest, accounting for nearly 70% of all subjects (Table 1), demonstrating the difficulty of biomechanical analysis in uncontrolled environments. It should also be noted that the skeletal model in OpenPose does not exactly match actual anatomical skeletal structures (see Discussion).
Furthermore, there are biases in the estimates depending on the distance between the camera and the subject, as well as errors in the pose estimation itself. In fact, when compared with the ROM estimated using a gyro sensor [20], a shift of approximately 10˚to 20˚was observed, and the variance tended to be large (Fig 2, Table 2). Therefore, instead of directly applying criteria based on other measurement methods, such as gyroscope sensors, OpenPose's baseline should be estimated to separate the signal from the noise. We detected unnatural errors biomechanically, by calculating thresholds based on statistical confidence intervals derived from the database (see Materials and Methods).
Although COG and stride length anomalies were relatively infrequent, they were distinctly different from the COG and stride length of natural gait and, thus, had to be detected and corrected. In a healthy person, COG is unlikely to fluctuate significantly throughout the gait cycle. We used clustering to identify the positions of the hip (Rh or Lh), knee (Rk or Lk), and ankle (Right Ankle [Ra] or Left Ankle [La]), which were considered to be off-center (see Materials and Methods, S1 Fig).
For stride length, we observed cases where the distance of the ankle joint (Ra and La) was underestimated or overestimated for a particular frame or for the entire frame. For the other cases, we focused on the maximum stride length in the gait cycle and derived a threshold based on statistical confidence intervals to identify the error (S2 Fig).

Physical constraints
Gait is a continuous motion in time that depends on the frame rate of the video recording in OpenPose, but it is difficult to imagine instantaneous motion beyond the physical constraints in the normal range. Therefore, motion with extremely discontinuous changes is considered to be due to errors. We considered two types of errors: reversals of the left and right legs ( Fig 1G) and discontinuous frame transitions ( Fig 1H). In the latter case, it was sufficient to detect the change point in the time series. However, it was not sufficient to detect the point at which the legs switched; thus, the deviated state was detected using the direction vector in periodic motion (see Materials and Methods). Another physically unnatural case was floating above ground surface ( Fig 1I). In this case, the normal range from the head to the ankle was estimated in advance based on the standard human skeletal model [19], and deviations from this range were detected (see Materials and Methods).

Estimation accuracy
The reliability score in OpenPose is calculated based on the distance from the correct location to each pixel in the image [21]. The pixels that are the shortest distance from the correct location are considered to have the highest reliability, whereas a low reliability score suggests that the estimated joint may not exist in the image or that it cannot be estimated. The variability of the actual reliability score tended to be lower for certain joints (Fig 3B). It was not easy to identify the cause of the error based on the reliability score, which is an inherent problem in the deep learning algorithm of OpenPose. However, it is possible to determine the reliability score from a statistical perspective. The overall distribution of the reliability scores was bimodal (Fig 3A), suggesting the existence of two potential groups of low and high reliability. We estimated these two groups based on k-means clustering and detected the group with low accuracy.

Accuracy of pose estimation during gait in an uncontrolled environment
We used a largescale database of OpenPose gait data to examine the reliability of OpenPose estimates of joint coordinates. However, the database used in this study only contained Open-Pose data, so it was not possible to evaluate the data using external criteria. Instead, using our workflow, we calculated percentages by defining joint coordinates that did not contain the anomalies shown in Table 1 as negative examples of the anomalies. The percentages of each joint determined to be normal and the percentage after correction using our workflow are summarized in Fig 4. The workflow will be described in the next section.
The accuracy for the joints on the opposite side to the camera direction was low, but on the same side, the accuracy varied, ranging from 53.8% to 93.5%. In particular, the knee (Rk or Lk) and ankle (Ra or La) contained some anomalous errors in nearly half of the subjects, strongly suggesting that they need to be addressed for downstream analysis to be performed properly.

Workflow for anomaly detection and correction
To perform gait analysis using OpenPose in an uncontrolled environment, many anomalous errors must be addressed during preprocessing. However, it is unclear which strategies should be used for detection and correction. Here, we present a workflow for detecting and correcting 10 types of anomalies (Fig 5).

Normalization step
The first normalization step transforms the coordinate system and skeletal length into a form that is comparable for all samples. Ne was set as the origin and transformed into joint coordinates corresponding to the ratio of the neck to the trunk length (see Materials and Methods). This allows for a general discussion of statistical properties and the setting of thresholds to deal with anomalous errors, which allows for efficient preprocessing.

Anomaly detection step
Following normalization, the anomalous error of switching the left and right legs was first detected and corrected. This is because leg swapping is a serious error in gait analysis and may affect the detection of other anomaly types. Subsequently, the other nine types were detected.   Table 1) is shown. The numbers in parentheses represent the accuracy after correcting the proposed workflow. https://doi.org/10.1371/journal.pcbi.1009989.g004

Correction of anomalous error step
The detected parts with anomalous errors could be considered missing values because they cannot be used in the downstream analysis. To some extent, they can be imputed using information from the previous and subsequent frames via averaging. However, if the overall number of missing values is extremely high in one gait cycle or if there are many continuous missing values, the reliability of the missing-value imputation is itself questionable, and such subjects should be excluded. Two filtering criteria were used: (1) the error percentage of each part of the total number of frames was greater than 40%, and (2) the percentage of consecutive missing frames within a gait cycle was more than 20% of the total number of frames (see Materials and Methods). Finally, we were able to impute the missing values of 66.8% of the participants.

Other adjustments
In addition, because it has been reported that video-based pose estimation causes distortions in the estimated coordinate values depending on the distance from the camera (Fig 6), and because the skeletal length within the same subject is not constant [16], we also corrected the skeletal length (see Materials and Methods).

Reproducibility of workflow
Simulation model. In order to validate the reliability of the proposed workflow, it is common to compare the results of it with ground-truth data such as BICON. However, since there is no ground-truth data used in result section; thus, we conducted a simulation experiment based on actual data (S1 Text) to validate the reproducibility of the workflow in this study. First, we extracted some samples from a real dataset. Second, we generated a pseudo dataset by adding various errors to these samples. The probability of occurrence of each anomalous error was calculated using relative frequencies (Table 1). We generated 10,000 subjects with 25 frames per gait cycle and evaluated the detection accuracy for each anomaly type and the reproducibility of the true joint coordinates.
Simulation results. First, we confirmed the reproducibility of the detection accuracy for individual anomalous errors each parts; the sensitivity and specificity were 82.6% and 95.1%, respectively. However, the accuracy for each type of anomaly varied from 71.1% to 95.4%, which indicates that the difficulty of anomaly detection varies from joint to joint (Table 3). Pearson's correlation coefficients of the xy-coordinate values before and after the correction were calculated to determine the accuracy for missing imputation, suggesting that there was a significant reproducibility for the joints overall (0.770 for the x-coordinate; p-value <2.2e-16, 0.961 for the y-coordinate; p-value <2.2e- 16). In addition, the reproducibility of the individual joints was evaluated. Regarding the accuracy at the level of individual joints, there was a tendency for the accuracy to be relatively low for undetected joints, leg length, COG, and ankle distance, which is thought to represent the variability due to the relatively low accuracy of anomaly detection (Table 4).

Implementation
The workflow presented in this paper has been deposited in R code (Github URL: https:// github.com/matsui-lab/PoseFixeR). A series of preprocessing steps were performed using the coordinate values obtained from the posture estimation using OpenPose as the input data. Detailed parameter settings are described in a vignette.

Discussion
We used a large database analysis to comprehensively classify technical anomalies using Open-Pose gait pose estimation and identified four main types: anatomical, biomechanical, and physical anomalies and errors dues to estimation. We have also presented a method of detecting these anomalies and suggested a workflow for their correction. According to our criteria, all of the 18 parts estimated by OpenPose contained some anomalies, suggesting that proper pre-processing is required before extracting gait features. Moreover, simulation experiments showed that the accuracy of anomaly detection and correction varied depending on anomaly type, implying the need to develop appropriate preprocessing methods for each type.
In particular, the nature of the two-dimensional video-based representations makes skeletal length distortions dependent on the distance between the camera and the subject, and produces anomalous joint coordinate estimates owing to unobserved joints on the opposite side to the camera. The latter anomalous measurement error could be rescued with up to 73% accuracy by our workflow, as shown in the numerical experiments, and it was difficult to capture the complete characteristics of one gait cycle by video recording only on one side. Therefore, it may be effective to develop an experimental design that focuses on specific parameters, such as the motions of specific joints on the video recording side.
The anatomical skeletal models should also be evaluated. In the comparison of inertial sensors and OpenPose in terms of ROMs, we observed a shift of approximately 10˚-20˚. One of the main reasons for this is the difference in the skeletal model. Taking the hip joint as an example, in the field of orthopedics and rehabilitation, ROM is generally measured by measuring the external angle composed of the axis between the trunk and femur. However, because the hip joint area is simplified in OpenPose, the ROM is calculated from the external angle composed of the axis directly connecting Ne and Rh/Lh, Rh/Lh, and Rk/Lk, which results in different criteria and generates a bias. Therefore, when analyzing gait using OpenPose, especially when interpreting biomechanical features, we should not simply compare the results with standard sensors, such as gyroscopes and goniometers, but should make comparisons based on OpenPose's baseline. We showed the anomalies in an uncontrolled environment as comprehensively as possible along with the workflow. However, there are several limitations. First, we did not necessarily cover all anomalies since the results are based on the analysis of a single database. Second, we didn't compare our results to ground-truth data (e.g., motion capture) because only the Open-Pose data was available in the public database. Our proposed workflow should be evaluated in further studies. Third, we determined threshold values (e.g., using in Eq(4)) based on a standard skeletal model [19], so gender and age groups were not considered. For more sophisticated algorithms, appropriate skeletal models should be used. Fourth, there is a problem with OpenPose itself. As Seethapathi et al. [17] pointed out, current pose tracking algorithms do not prioritize measurement of the quantities that are important in movement science, such as three-dimensional position, velocity, and acceleration. Therefore, a new algorithm should be developed that considers important factors in kinematics, so that a more suitable system can be constructed.
In order to increase the clinical applications of video-based 2D pose estimation technology, it will be necessary to find situations where it can be used most effectively from a clinical point of view, and to develop an appropriate analysis algorithm in the future [22]. From a practical standpoint, a reproducible and robust analysis method will be crucial. For example, the development of an algorithm that effectively exploits the latent time-series structure of tracking errors for skeletal coordinates is an important issue for future research. On the other hand, this study also employed some threshold-based methods, such as standard skeletal length ratios derived from existing anatomical knowledge and confidence score thresholds based on statistical distributions. Since the OpenPose skeletal estimates do not take into account anatomical or clinical knowledge, methods that combine existing knowledge may be useful. For example, in the category of "side of legs" (g in Fig 1), which occurs when the left and right legs cross each other, self-evaluation of OpenPose such as frame by frame analysis or coordinate distance between frames cannot detect this anomaly, although it can affect joint angle estimation.
It is also important to study analysis methods for disease signals through clinical research designs, such as comparisons between healthy and diseased groups. For example, there may be an affinity between developing research designs that focus on specific parts of the body and researching algorithms dedicated to the early detection of disease-related signatures. Additionally, the development of open-source software and public databases is also considered to be an important research gap that must be filled to allow further clinical applications and the development of our method as a reproducible research method.
The OpenPose in uncontrolled gait analysis revealed various measurement anomalies in all samples due to technical limitations. However, preprocessing using a combination of anatomical, physical, and biomechanical knowledge and statistical algorithms suggested that nearly 70% of the samples could be rescued, although the accuracy varied for each anomaly type. With the development of appropriate study designs and more sophisticated analysis algorithms in the future, it is expected that accuracy can be improved, even in uncontrolled environments. Since our suggested category (Fig 1) will likely include anomalous errors in the controlled environment, it is considered to be widely applicable, and not limited to pose estimation in unconstrained environments. We hope that our study will be helpful when further studies on large populations have been conducted to accumulate evidence.

Dataset
In this study, we used the Osaka University-Institute of Scientific and Industrial Research (OU-ISIR) Gait Database [18], a multi-view large population dataset with pose sequences [18] deposited in the OU-ISIR Biometric Database. By capturing the subjects walking approximately 10 m back and forth, we can observe the gait cycle at a normal speed for each sample. The images had a frame rate of 25 fps and an image size of 1280 × 980 pixels. OpenPose shows the x and y coordinates and confidence levels for 18 joints in each frame: nose, neck, right shoulder, right elbow, right wrist, left shoulder, left elbow, left wrist, right groin, right knee, right foot, left groin, left knee, left foot, right eye, left eye, right ear, and left ear.

Workflow details
The details of the workflow are described below. First, we define the mathematical notation.

Normalization
In video-based pose estimation, normalization is necessary because the skeletal length varies depending on the height of the subject, the distance from the subject, and the position of the camera. In this study, we followed the method described by An W et al. [18] and normalized the skeletal coordinate values in three steps: (1) centering with the Ne coordinates as the origin, (2) estimating the scale factor of the skeletal length, and (3) normalizing the skeletal coordinates. Specifically, centering was performed using Eq (1).
Next, to calculate the "relative scale" for each individual frame, the distance from the midpoint of the post-transformed coordinates of the left hip ðX � it ½LH�; Y � it ½LH�Þ and the right hip ðX � it ½RH�; Y � it ½RH�Þ to the neck (0, 0) was calculated as scale it .
scale it ¼ 1 2 ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi Finally, we normalized all the joint coordinates such that the relative scale it became 1. That is, each joint coordinate was divided by the relative scale to obtain the normalized coordinates ðX y it ½��; Y y it ½��Þ.
Henceforth, we will use ðX y it ½��; Y y it ½��Þ in the following description.

Anatomical constraints
According to the skeletal length in the standard skeletal model, if the length of the trunk, which is the distance from the neck to the hip joint, is 1,then the distance from the neck to the top of the head is 0.362, and the distance from the neck to the ankle joint is 2.283 [19]. If the xcoordinates of the top of the head and ankle joint, which are the two ends on the y-axis, are the same as the x-coordinates of the neck, then the neck coordinates are (0, 0), the head coordinates are (0, -0.362), and the ankle coordinates are (0, 2.283). Therefore, the y-coordinates of all joints were considered to be in the range [-0.362, 2.283]. If we introduce an error ratio (ER) to account for individual differences, we can consider that the coordinates of any joint Y y it ½�� lie within the following range: Coordinates that do not satisfy this condition deviate from the expected range.

Biomechanical feature
Here we describe anomaly detection for range of motion (ROM), which is the external angle of the axis connecting Ne and Rh (or Lh) and Rk (or Lk). To identify the joint coordinates deviating from the standard ROM, 95% confidence intervals were constructed based on the empirical distributions derived from the maximum flexion angles of each joint of the lower extremities (both hip and knee joints) obtained by the following calculations, and those outside the confidence intervals were considered anomalies. First, the Rh flexion angle (calculated in the same way as the Lh flexion angle) was calculated as follows: cos it ½Rh� ¼ ðX y it ½Ne� À X y it ½Rh�ÞðX y it ½Rk� À X y it ½Rh�Þ þ ðY y it ½Ne� À Y y it ½Rh�ÞðY y it ½Rk� À Y y it ½Rh�Þ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ðX y it ½Rk� À X y it ½Rh�Þ 2 þ ðX y it ½Ne� À X y it ½Rh�Þ 2 q þ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi The Rk joint flexion angle (calculated in the same way as the Lk joint flexion angle) was obtained as follows: it ½Rk�Þ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ðX y it ½Rh� À X y it ½Rk�Þ 2 þ ðX y it ½Ra� À X y it ½Rk�Þ 2 q þ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi From these joint angles, the empirical distribution F was constructed. The joint angles were set as R it , which is defined as arccos(cos it [�])×180˚/π, and The empirical distribution F for each joint was considered to represent the range of motion distribution in one gait cycle at the population level, including all subjects. Based on this, we constructed a 95% confidence interval CI 95% for each joint and obtained CI 95% ¼ ½F À 1 ð0:025Þ; F À 1 ð0:975Þ�: Observed values outside the confidence interval were considered errors.
For the center of gravity (COG), we considered a point in three-dimensional space consisting of the midpoints of the x-coordinates of the hip (Rh or Lh), knee (Rk or Lk), and ankle (Ra or La) with respect to the perpendicular line from Ne to the ground and identified the group whose distance from the origin deviated using the k-means method. The number of clusters was determined using the gap statistic [23]. The distance dist from the origin Ne to a point can be described as follows: dist ¼ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi For anomalous errors related to ankle joint distance, we used Length ankle ¼ ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ðX y it ½Ra� À X y it ½La�Þ 2 q ð9Þ to construct empirical distributions, derive 95% confidence intervals, and detect values those outside the intervals as deviating errors. However, because some anomalies in undetected joints may result in extremely large leg lengths, confidence intervals were derived after excluding those errors in advance.

Physical constraints
Regarding the method used to detect when the left and right legs are reversed, the inversion of the leg joint coordinates at frame t was detected by comparing the leg joint coordinates of the two frames before and after. For this purpose, we detected whether inversion occurs at 3�t�T −2 frames. As we could use time-series information, we removed the effects of missing values and outliers in advance. We linearly interpolated the knee joint coordinates of the vectors X y i� ½La�; X y i� ½Ra� at each frame and then applied spline smoothing to obtain Z i� [La], Z i� [Ra]. If the skeletal coordinates measured in one gait cycle are reversed for the left and right legs, the coordinates should not move like a pendulum but should be biased to either the left or right. Thus, one of the following should be true for the inversion of the left and right legs: Here, I(A) is an indicator function that gives 1 if the condition A is satisfied, and 0 if not. In addition, since it was considered that there is a limit to the movement of the legs during gait, was assumed to be satisfied. After satisfying these conditions, the direction of the leg joint movement changes after frame t, that is, and signðZ it ½La� À Z itÀ 1 ½La�Þ are satisfied, and the joint coordinates of the left and right legs are considered to be reversed, where sign(�) is a sign function.
To detect errors in ground contact, the reference value of the y-axis coordinates of the legs was set to 2.283. When the y-axis coordinates of both legs deviated sufficiently from the reference value, either upward or downward, it was determined that the person was not grounded.
The error of the frame transition was defined a value as more than a certain distance from the coordinate of frame t-1 or frame t+1. In other words, ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ðX y it ½�� À X y itÀ 1 ½��Þ 2 þ ðY y it ½�� À Y y itÀ 1 ½��Þ 2 q � JUMP or ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ffi ffi ffi ffi ffi ffi ffi ffi ffi ffiffi ðX y it ½�� À X y itþ1 ½��Þ 2 þ ðY y it ½�� À Y y itþ1 ½��Þ When one or more of the following conditions were satisfied, the joint coordinate was treated as an anomalous error. In this case, JUMP = 0.5 (1/25 s comparison) and 0.7 (2/25 s comparison).

Selecting subjects for imputation
We excluded subjects with many anomalous error frames that we defined because it would be difficult to extract gait features in the downstream analysis. Exclusion criteria were as follows: (1) the error rate of each region was more than 40% of the total number of frames and (2) the missing values were greater than 20% of the total number of frames in one gait cycle (S5 Fig). The first criterion was set considering that errors could be detected in at least 20% of samples, even in controlled environments. In addition, technical errors caused by other factors may occur in uncontrolled environments. For the second criterion, we considered that the maximum percentage of each phase per gait cycle was approximately 20% [24].